// web/scripts/forum/mark.ts

// @ts-ignore
const {PrismaClient} = require('@prisma/client');
// @ts-ignore
const db = new PrismaClient()
// @ts-ignore
const LoremIpsum = require("lorem-ipsum").LoremIpsum;
// @ts-ignore
const {faker} = require('@faker-js/faker/locale/zh_CN');

const lorem = new LoremIpsum({
    sentencesPerParagraph: {
        max: 8,
        min: 4
    },
    wordsPerSentence: {
        max: 16,
        min: 4
    }
});

// @ts-ignore
let count = 20


// @ts-ignore
async function main() {
    const users = await db.user.findMany({take: 20})

    function createRandomPost() {
        return {
            name: users[Math.floor(Math.random() * 10)].name,
            username: users[Math.floor(Math.random() * 10)].name,
            userImg: users[Math.floor(Math.random() * 10)].image,
            img: faker.image.url(),
            text: lorem.generateParagraphs(3),
            timestamp: new Date(),
            userId: users[Math.floor(Math.random() * 10)].id,
        };
    }

    const posts = faker.helpers.multiple(createRandomPost, {
        count,
    });

    // 虚拟帖子数据
    await db.post.createMany({
        data: [...posts]
    })

    console.log(`ok`)
}

main()
